package com.lc1993929.mr.pv;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * KEYIN，VALUEIN 对应的是map阶段输出的数据的key和value的类型
 * <p>
 * KEYOUT，VALUEOUT  是用户的reduce阶段的逻辑处理结果中的key和value的类型
 * <p>
 * <p>
 * Created by LiuChang on 2017/11/2/002.
 */
public class PvReducer extends Reducer<Text, IntWritable, Text, IntWritable> {

    /**
     * mapReduce框架在reduce端程序在整理好一组相同key的数据后，调用一次用户写的这个reduce()方法
     *
     * @param key
     * @param values
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int count = 0;
        for (IntWritable value : values) {
            count += value.get();
        }

        context.write(key, new IntWritable(count));

    }
}
